#!usr/bin/env python  
# -*- coding:utf-8 -*-
""" 
@author:robot
@file: title02_2热点网站统计.py 
@version:
@time: 2023/05/26 
"""
from collections import defaultdict

top_map = defaultdict(int)


def solve(_input):
    if not _input.isdigit():
        top_map[_input] += 1
    else:
        n = int(_input)
        sorted_list = sorted(
            top_map.items(),
            key=lambda x: x[1],
            reverse=True
        )
        for i in range(n):
            print(sorted_list[i][0], end="")
            if i != n - 1:
                print(",", end="")
        print()


while True:
    try:
        solve(input().strip())
    except:
        break
